package com.mogul.lahub

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ImageView
import androidx.core.view.get
import com.hjq.toast.ToastUtils
import com.mogul.lahub.databinding.ActivityMainBinding
import com.mogul.lahub.fragment.*

class MainActivity : AppCompatActivity() {

    private var pageCode = 9

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val mainBinding = ActivityMainBinding.inflate(layoutInflater)
        val rootview = mainBinding.root
        setContentView(rootview)
        (mainBinding.clBottomMendwdnu.get(0) as ImageView).setOnClickListener {
            ToastUtils.show("点击主页")
        }
        (mainBinding.clBottomMendwdnu.get(1) as ImageView).setOnClickListener {
            ToastUtils.show("点击我的")
        }

        initFragmentPage()

    }

    private fun initFragmentPage() {
        val transaction = supportFragmentManager.beginTransaction()
        when(pageCode) {
            0-> {
                val initLoanFragment = InitLoanFragment()
                transaction.replace(R.id.fl_container_vidnwew_tag, initLoanFragment, initLoanFragment.id.toString())
                transaction.commitAllowingStateLoss()
            }
            1-> {
                val type = 1
                if (type==0) {
                    val auditLoanOpenFragment = AuditLoanOpenFragment()
                    transaction.replace(R.id.fl_container_vidnwew_tag, auditLoanOpenFragment, auditLoanOpenFragment.id.toString())
                    transaction.commitAllowingStateLoss()
                }else {
                    val auditLoanCloseFragment = AuditLoanCloseFragment()
                    transaction.replace(R.id.fl_container_vidnwew_tag, auditLoanCloseFragment, auditLoanCloseFragment.id.toString())
                    transaction.commitAllowingStateLoss()
                }
            }
            3-> {
                val lendLoanFragment = LendLoanFragment()
                transaction.replace(R.id.fl_container_vidnwew_tag, lendLoanFragment, lendLoanFragment.id.toString())
                transaction.commitAllowingStateLoss()
            }
            9-> {
                val cancelLoanFragment = CancelLoanFragment()
                transaction.replace(R.id.fl_container_vidnwew_tag, cancelLoanFragment, cancelLoanFragment.id.toString())
                transaction.commitAllowingStateLoss()
            }
            12-> {
                val withdrawCashFragment = WithdrawCashFragment()
                transaction.replace(R.id.fl_container_vidnwew_tag, withdrawCashFragment, withdrawCashFragment.id.toString())
                transaction.commitAllowingStateLoss()
            }
        }

    }
}